-content_for :modal_title do
  -if params[:system_id].present?
    Select Controls
  -else
    Select Systems/Processes

-if params[:system_id].present?
  -content_for :modal_help, :select_system_controls
-else
  -content_for :modal_help, :select_control_systems

%script#system_option{ :type => 'text/html', :'data-prefix' => 'system' }
  %li{ :'data-id' => '<%= system.id %>', :'data-title' => '<%= system.title %>', :'data-slug' => '<%= system.slug %>' }
    .row-fluid
      .span8
        .object-info
          %span.name <%= system.title %>
          %span.option <%= system.slug %>
        
      .span4.actions
        .pull-right
          %a.widgetbtn.btn.btn-mini{:href => edit_flow_system_path('<%=system.id%>'), :'data-toggle' => 'modal-ajax-listeditform', :'data-selector-target' => '.source, .target', :'data-modal-class' => 'modal-wide' }
            %i.grcicon-edit
          %a.widgetbtn.btn.btn-mini.add-me{:href => "#", :'data-toggle' => 'selector-list-select'}
            %i.grcicon-chevron-right

%script#system_option_data{ :type => 'text/html' }
  %span.name <%= system.title %>
  %span.option <%= system.slug %>

%script#system_selected{ :type => 'text/html', :'data-mappings' => 'child:system,object:system', :'data-member' => 'system_control' }
  %li{ :'data-id' => '<%= id %>', :'data-object-id' => '<%= system.id %>' }
    .row-fluid
      .span6.object_info{ :'data-template-id' => 'system_option_data' }
      .span6.actions
        %span.state
        .pull-right
          %input{ :type => 'hidden', :name => 'items[<%= id %>][id]', :value => '<% if (id.toString().substr(0,3) != "new") { %><%= id %><% } %>'.html_safe }
          %input{ :type => 'hidden', :name => 'items[<%= id %>][control_id]', :value => object.id }
          %input{ :type => 'hidden', :name => 'items[<%= id %>][system_id]', :value => '<%= system.id %>' }
          %input._destroy{ :type => 'hidden', :name => 'items[<%= id %>][_destroy]', :value => '' }
          %a.widgetbtn.btn.btn-mini{ :href => edit_flow_system_path('<%=system.id%>'), :'data-toggle' => 'modal-ajax-listeditform', :'data-selector-target' => '.source, .target', :'data-modal-class' => 'modal-wide' }
            %i.grcicon-edit
          %a.widgetbtn.btn.btn-mini{ :href => '#', :'data-toggle' => 'selector-list-remove' }
            %i.grcicon-remove

%script#control_option{ :type => 'text/html', :'data-prefix' => 'control' }
  %li{ :'data-id' => '<%= control.id %>', :'data-title' => '<%= control.title %>', :'data-slug' => '<%= control.slug %>' }
    .row-fluid
      .span8
        %span.name <%= control.title %>
        %span.option <%= control.slug %>
      .span4.actions
        .pull-right
          %a.widgetbtn.btn.btn-mini{:href => edit_flow_control_path('<%=control.id%>'), :'data-toggle' => 'modal-ajax-listeditform', :'data-selector-target' => '.source, .target', :'data-modal-class' => 'modal-wide' }
            %i.grcicon-edit
          %a.widgetbtn.btn.btn-mini.add-me{:href => "#", :'data-toggle' => 'selector-list-select'}
            %i.grcicon-chevron-right

%script#control_option_data{ :type => 'text/html' }
  .object-info
    %span.name <%= control.title %>
    %span.option <%= control.slug %>

%script#control_selected{ :type => 'text/html', :'data-mappings' => 'child:control,object:control', :'data-member' => 'system_control' }
  %li{ :'data-id' => '<%= id %>', :'data-object-id' => '<%= control.id %>' }
    .row-fluid
      .span6.object_info{ :'data-template-id' => 'control_option_data' }
      .span6.actions
        %span.state
        .pull-right
          %input{ :type => 'hidden', :name => 'items[<%= id %>][id]', :value => '<% if (id.toString().substr(0,3) != "new") { %><%= id %><% } %>'.html_safe }
          %input{ :type => 'hidden', :name => 'items[<%= id %>][system_id]', :value => object.id }
          %input{ :type => 'hidden', :name => 'items[<%= id %>][control_id]', :value => '<%= control.id %>' }
          %input._destroy{ :type => 'hidden', :name => 'items[<%= id %>][_destroy]', :value => '' }
          %a.widgetbtn.btn.btn-mini{ :href => edit_flow_control_path('<%=control.id%>'), :'data-toggle' => 'modal-ajax-listeditform', :'data-selector-target' => '.source, .target', :'data-modal-class' => 'modal-wide' }
            %i.grcicon-edit
          %a.widgetbtn.btn.btn-mini{ :href => '#', :'data-toggle' => 'selector-list-remove' }
            %i.grcicon-remove

-if params[:system_id].present?
  .row-fluid.modal-source
    .span6
      .row-fluid
        .span7
          %h3
            Add Control
            %a.widgetbtn.widgetbtnselector.btn.btn-add{ :href => new_flow_control_path, :'data-toggle' => 'modal-ajax-listnewform', :'data-selector-target' => '.source, .target', :'data-modal-class' => 'modal-wide' }
              %i.grcicon-add
        .span5
          %input.widgetsearch.input-block-level{:type => "text", :placeholder => "Search Controls"}

      .filter-block
        .row-fluid
          .span12
            .tabbable.tabs-left
              .tab-content
                #category1.tab-pane.active
                  .people-list
                    %ul.source{ :'data-list-data-href' => flow_controls_path(:format => :json), :'data-template-id' => 'control_option' }
    .span6
      %h3
        Controls for this system
      .people-list.currentlist
        %ul.target{ :'data-list-data-href' => flow_system_controls_path(:system_id => object.id, :format => :json), :'data-selector-target' => '.source, .target', :'data-template-id' => 'control_selected'}
-else
  .row-fluid.modal-source
    .span6
      .row-fluid
        .span7
          %h3
            Add System/Process
            %a.widgetbtn.widgetbtnselector.btn.btn-add{ :href => new_flow_system_path, :'data-toggle' => 'modal-ajax-listnewform', :'data-selector-target' => '.source, .target', :'data-modal-class' => 'modal-wide' }
              %i.grcicon-add
        .span5
          %input.widgetsearch.input-block-level{:type => "text", :placeholder => "Search Systems"}

      .filter-block
        .row-fluid
          .span12
            .tabbable.tabs-left
              .tab-content
                #category1.tab-pane.active
                  .people-list
                    %ul.source{ :'data-list-data-href' => flow_systems_path(:format => :json), :'data-template-id' => 'system_option' }
    .span6
      %h3
        Systems/Processes implementing this control
      .people-list.currentlist
        %ul.target{ :'data-list-data-href' => flow_system_controls_path(:control_id => object.id, :format => :json), :'data-selector-target' => '.source, .target', :'data-template-id' => 'system_selected'}

.spinner
